package com.xmy.cultivate.schedule;

import com.xmy.cultivate.entity.Quarter;
import com.xmy.cultivate.entity.views.IntegralStatisticsRs;
import com.xmy.cultivate.service.IEnrollInfoService;
import com.xmy.cultivate.service.IMqPushService;
import com.xmy.cultivate.service.IQuarterService;
import com.xmy.cultivate.util.SpringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;

public class IntegralStatisticsJob implements Job {

    @Autowired
    IMqPushService iMqPushService = SpringUtils.getBean(IMqPushService.class);

    @Autowired
    IQuarterService iQuarterService = SpringUtils.getBean(IQuarterService.class);

    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private void before() {
        System.out.println("任务1：开始执行-积分汇总-" + dateFormat.format(new Date()));
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        Quarter quarterNow = iQuarterService.getNowQuarter();
        if (quarterNow!=null){
            IntegralStatisticsRs integralStatisticsRs = new IntegralStatisticsRs();
            integralStatisticsRs.setId(0L);
            integralStatisticsRs.setYearPart(quarterNow.getYearPart());
            integralStatisticsRs.setQuarterNum(quarterNow.getNum());
            iMqPushService.integralStatistics(integralStatisticsRs);
        }
    }

    private void after() {
        System.out.println("任务1：执行结束补-积分汇总");
    }
}
